package com.shouhuobao.bhi.collect;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
/**
 * 自定义Gallery
 * 适用于地图页面的网点显示部分
 * @author wind
 *
 */
public class CollectMapGallery extends Gallery {
	private float x = 0;
	private boolean isOnGalleryTouch = false;

	public CollectMapGallery(Context context) {
		super(context);
	}

	public CollectMapGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		int action = ev.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			x = ev.getX();
			super.onTouchEvent(ev);
			break;
		case MotionEvent.ACTION_UP:
			break;
		case MotionEvent.ACTION_CANCEL:
			break;
		case MotionEvent.ACTION_MOVE:
			float daltX = Math.abs(x - ev.getX());
			if (daltX < 5) {
				return false;
			} else {
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		int keyEvent;
		if (isScroollingLeft(e1, e2)) {
			keyEvent = KeyEvent.KEYCODE_DPAD_LEFT;
		} else {
			keyEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
		}
		onKeyDown(keyEvent, null);
		return true;
	}

	public boolean isScroollingLeft(MotionEvent e1, MotionEvent e2) {
		return e2.getX() > e1.getX();
	}

	public boolean isOnGalleryTouch() {
		return isOnGalleryTouch;
	}

}
